﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using PMS.IRepository;
using PMS.Utils;


namespace PMS.DalFactory
{
    public class DataFactory
    {
        public static readonly string AssemblyPath = ConfigurationManager.AppSettings["DAL"];

        public static object CreateObject(string assemblyPath, string classNamespace)
        {
            object objType = DataCache.GetCache(classNamespace);//从缓存读取
            if (objType == null)
            {
                object obj = Assembly.Load(assemblyPath).CreateInstance(classNamespace);
                DataCache.SetCache(classNamespace, obj);
            }

            return objType;
        }

        public static IBaseUserRepository CreateBaseUserRepository()
        {
            string classNamespace = AssemblyPath + ".BaseUser";
            object objType = CreateObject(AssemblyPath, classNamespace);
            return (IBaseUserRepository)objType;
        }

        //以下同理
        //因为暂时没有用到工厂模式 就先写个栗子留着

    }
}
